	* do "Prepare_figures.do"

	**************************
	* LOG FILE
	**************************

local name="Prepare_figures"

capture log close
log using "${log_files}/Log_`name'.log", replace

	**************************
	* PREPARE FIGURES
	**************************

local xmin=10 
local xmax=11.2

local width=1200*5.5/4

local bw3_1="gs7"
local bw3_2="gs3"
local bw3_3="gs0"

local bw5_1="gs10"
local bw5_2="gs5"
local bw5_3="gs8"
local bw5_4="gs2"
local bw5_5="gs0"

local pattern_bw3_1="l"
local pattern_bw3_2="-#"
local pattern_bw3_3="l"

local pattern_bw5_1="l"
local pattern_bw5_2="-#"
local pattern_bw5_3="_#"
local pattern_bw5_4="_#"
local pattern_bw5_5="l"

local options_all="graphregion(color(white))"
local ylabel=`"0 "0" 0.25 "0.25" 0.5 "0.5" 0.75 "0.75" 1 "1" "'

foreach xx in "" "_smooth" {
foreach zz in "exog" "endog" {

	**************************
	* 3 GROUPS GRAPH 
	**************************

qui use "${output}/output_run1_cdf_r2_ALL_gg0_xxALL_`zz'.dta", clear

qui keep if x_cdf>=`xmin'

graph twoway ///
	(line y_cdf`xx'_0 x_cdf, sort connect(J) lpattern("`pattern_bw3_1'") lcolor("`bw3_1'") lwidth(medthick)) /// 		/* light */
	(line y_cdf`xx'_1 x_cdf, sort connect(J) lpattern("`pattern_bw3_2'") lcolor("`bw3_2'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_2 x_cdf, sort connect(J) lpattern("`pattern_bw3_3'") lcolor("`bw3_3'") lwidth(medthick)) /// 		/* black */
	, legend(cols(1) ring(0) bplacement(seast) order(1 2 3) ///
	label(1 "Equal ({it:N}=96)") label(2 "Home ({it:N}=10,510)") label(3 "Unequal ({it:N}=485)")  ///
	size(3) rowgap(1) region(lcolor(gs16))) ///
	name(fig_main`xx'_`zz', replace) ytick(0(0.25)1) ylabel(`ylabel', labsize(medsmall)) ///
	ymtick(0(0.05)1) xlabel(`xmin'(0.2)`xmax', labsize(medsmall)) xmtick(`xmin'(0.05)`xmax') xtitle("Log predicted earnings", size(medsmall) height(4)) ///
	`options_all'

qui graph export ${output}/fig_main`xx'_`zz'.eps, replace name(fig_main`xx'_`zz')
qui graph drop fig_main`xx'_`zz'

	**************************
	* 5 GROUPS GRAPH 
	**************************

qui use "${output}/output_run1_cdf_r2_ALL_gg1_xxALL_`zz'.dta", clear

qui keep if x_cdf>=`xmin'

graph twoway ///
	(line y_cdf`xx'_0 x_cdf, sort connect(J) lpattern("`pattern_bw5_1'") lcolor("`bw5_1'") lwidth(medthick)) /// 		/* light */
	(line y_cdf`xx'_1 x_cdf, sort connect(J) lpattern("`pattern_bw5_2'") lcolor("`bw5_2'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_4 x_cdf, sort connect(J) lpattern("`pattern_bw5_3'") lcolor("`bw5_3'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_3 x_cdf, sort connect(J) lpattern("`pattern_bw5_4'") lcolor("`bw5_4'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_2 x_cdf, sort connect(J) lpattern("`pattern_bw5_5'") lcolor("`bw5_5'") lwidth(medthick)) /// 		/* black */
	, legend(cols(1) ring(0) bplacement(seast) order(1 3 2 4 5) ///
	label(1 "Very equal ({it:N}=38)") label(2 "Home ({it:N}=10,510)") label(3 "Somewhat equal ({it:N}=58)") ///
	label(4 "Somewhat unequal ({it:N}=352)") label(5 "Very unequal ({it:N}=133)") ///
	size(2.5) rowgap(0.5)  region(lcolor(gs16))) ///
	name(fig_5groups`xx'_`zz', replace) ytick(0(0.25)1) ylabel(`ylabel', labsize(medsmall)) ///
	ymtick(0(0.05)1) xlabel(`xmin'(0.2)`xmax', labsize(medsmall)) xmtick(`xmin'(0.05)`xmax') xtitle("Log predicted earnings", size(medsmall) height(4)) ///
	`options_all'

qui graph export ${output}/fig_5groups`xx'_`zz'.eps, replace name(fig_5groups`xx'_`zz')
qui graph drop fig_5groups`xx'_`zz'

	**************************
	* 2 LINE GRAPH - CH+AUS
	**************************

qui use "${output}/output_run5_cdf_r2_ALL_gg0_xxCH_AUS_`zz'.dta", clear

qui keep if x_cdf>=`xmin'

qui replace y_cdf`xx'_0=.

graph twoway ///
	(line y_cdf`xx'_1 x_cdf, sort connect(J) lpattern("`pattern_bw3_2'") lcolor("`bw3_2'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_2 x_cdf, sort connect(J) lpattern("`pattern_bw3_3'") lcolor("`bw3_3'") lwidth(medthick)) /// 		/* black */
	, legend(cols(1) ring(0) bplacement(seast) order(1 2 3) ///
	label(1 "Home ({it:N}=10,510)") label(2 "Austria and Switzerland ({it:N}=194)")  ///
	size(3) rowgap(1) region(lcolor(gs16))) ///
	name(fig_CH_AUS`xx'_`zz', replace) ytick(0(0.25)1) ylabel(`ylabel', labsize(medsmall)) ///
	ymtick(0(0.05)1) xlabel(`xmin'(0.2)`xmax', labsize(medsmall)) xmtick(`xmin'(0.05)`xmax') xtitle("Log predicted earnings", size(medsmall) height(4)) ///
	`options_all'

qui graph export ${output}/fig_CH_AUS`xx'_`zz'.eps, replace name(fig_CH_AUS`xx'_`zz')
qui graph drop fig_CH_AUS`xx'_`zz'

	**************************
	* 3 GROUPS GRAPH - EUROPE
	**************************

qui use "${output}/output_run3_cdf_r2_ALL_gg0_xxEUROPE_`zz'.dta", clear

qui keep if x_cdf>=`xmin'

graph twoway ///
	(line y_cdf`xx'_0 x_cdf, sort connect(J) lpattern("`pattern_bw3_1'") lcolor("`bw3_1'") lwidth(medthick)) /// 		/* light */
	(line y_cdf`xx'_1 x_cdf, sort connect(J) lpattern("`pattern_bw3_2'") lcolor("`bw3_2'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_2 x_cdf, sort connect(J) lpattern("`pattern_bw3_3'") lcolor("`bw3_3'") lwidth(medthick)) /// 		/* black */
	, legend(cols(1) ring(0) bplacement(seast) order(1 2 3) ///
	label(1 "Equal ({it:N}=89)") label(2 "Home ({it:N}=10,510)") label(3 "Unequal ({it:N}=386)")  ///
	size(3) rowgap(1) region(lcolor(gs16))) ///
	name(fig_EUROPE`xx'_`zz', replace) ytick(0(0.25)1) ylabel(`ylabel', labsize(medsmall)) ///
	ymtick(0(0.05)1) xlabel(`xmin'(0.2)`xmax', labsize(medsmall)) xmtick(`xmin'(0.05)`xmax') xtitle("Log predicted earnings", size(medsmall) height(4)) ///
	`options_all'

qui graph export ${output}/fig_EUROPE`xx'_`zz'.eps, replace name(fig_EUROPE`xx'_`zz')
qui graph drop fig_EUROPE`xx'_`zz'

	**************************
	* 2 LINE GRAPH - US
	**************************

qui use "${output}/output_run4_cdf_r2_ALL_gg0_xxUS_`zz'.dta", clear

qui keep if x_cdf>=`xmin'

qui replace y_cdf`xx'_0=.

graph twoway ///
	(line y_cdf`xx'_1 x_cdf, sort connect(J) lpattern("`pattern_bw3_2'") lcolor("`bw3_2'") lwidth(medthick)) /// 		/* middle */
	(line y_cdf`xx'_2 x_cdf, sort connect(J) lpattern("`pattern_bw3_3'") lcolor("`bw3_3'") lwidth(medthick)) /// 		/* black */
	, legend(cols(1) ring(0) bplacement(seast) order(1 2 3) ///
	label(1 "Home ({it:N}=10,510)") label(2 "US ({it:N}=87)")  ///
	size(3) rowgap(1) region(lcolor(gs16))) ///
	name(fig_US`xx'_`zz', replace) ytick(0(0.25)1) ylabel(`ylabel', labsize(medsmall)) ///
	ymtick(0(0.05)1) xlabel(`xmin'(0.2)`xmax', labsize(medsmall)) xmtick(`xmin'(0.05)`xmax') xtitle("Log predicted earnings", size(medsmall) height(4)) ///
	`options_all'

qui graph export "${output}/fig_US`xx'_`zz'.eps", replace name(fig_US`xx'_`zz')
qui graph drop fig_US`xx'_`zz'

} /* exog endog */
} /* step vs smooth */

	**************************
	* RENAME FILES
	**************************

local dir `c(pwd)'
cd "${output}"

!cp "fig_main_exog.eps" "fig_2_a_1.eps"
!cp "fig_main_endog.eps" "fig_2_b_1.eps"
!cp "fig_5groups_exog.eps" "fig_2_a_2.eps"
!cp "fig_5groups_endog.eps" "fig_2_b_2.eps"
!cp "fig_EUROPE_endog.eps" "fig_4_a.eps"
!cp "fig_CH_AUS_endog.eps" "fig_4_b.eps"
!cp "fig_US_endog.eps" "fig_6_a_1.eps"

cd "`dir'"
	
	*
